/**
 * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * For the applicable distribution terms see the license.txt -file, included in
 * the distribution.
 */

#include "rotationdata.h"
#include <QRotationReading>
#include <QDebug>

RotationData::RotationData(QObject *parent) :
    QObject(parent), rotationSensor(new QRotationSensor(parent)),
    xRot(45.0f), yRot(45.0f), tilted(false)
{
    QObject::connect(rotationSensor, SIGNAL(readingChanged()), SLOT(updateRotation()));
    rotationSensor->start();
}

void RotationData::updateRotation()
{
    QRotationReading* reading = rotationSensor->reading();
    float yDiff = reading->y() - yRot;

    if (reading->x() < -12 && xRot > -10)
        emit tiltedLeft();
    if (reading->x() > 12 && xRot < 10)
        emit tiltedRight();
    xRot = reading->x();

    yRot += 0.9f*yDiff;
    emit rotationChanged(QVariant(yRot));
}
